<%@ page
	import="java.util.*,com.db.tracker.vo.*,java.util.*,com.db.tracker.util.*,java.text.*,java.io.*"%>
<%
		try {
		session = request.getSession();

		//	temporary removed enable this line for login, and remove if(false){
		if (session.getAttribute("USER_ID") == null
		|| !((String) session.getAttribute("SESSION_ID"))
				.equals(session.getId())) {

			//	if(false){
			try {
		response.sendRedirect("LoginPage.jsp");
			} catch (IOException ioe) {
		ioe.printStackTrace();
			}

		} else {


			
			DBUtil dbutil = new DBUtil(getServletContext());
			String userid = (String) session.getAttribute("USER_ID") == null ? ""
			: (String) session.getAttribute("USER_ID");
%>
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
<title>Release Schedule Page</title>
<script>

	function trim(sString)
		  {
			sTrimmedString = "";
		   if (sString != "") {
			  var iStart = 0;
			  var iEnd = sString.length - 1;
			 // var sWhitespace = " \t\f\n\r\v";
			 var sWhitespace = "   ";


			  while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
				 iStart++;
				 if (iStart > iEnd) 
					break;
			  }

			  // If the string not just whitespace
			  if (iStart <= iEnd) {
				 while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
					iEnd--;
				 sTrimmedString = sString.substring(iStart,++iEnd);
			  }
		   }
		   return sTrimmedString;
		 }

	function changeStatus(){
		document.ReleaseStatusForm.action="ReleaseAdmin.jsp";
		document.ReleaseStatusForm.submit();
	}

	function checkForEmpty(ScheduleDescr,ServerName,ServerUserId,ServerUserPwd,Branch){
		  	
					// alert("obj.value.length"+obj.value);
			
				ScheduleDescr.value = trim(ScheduleDescr.value);
				ServerName.value = trim(ServerName.value);
				ServerUserId.value = trim(ServerUserId.value);
				ServerUserPwd.value = trim(ServerUserPwd.value);
				Branch.value = trim(Branch.value);
	
				if (ScheduleDescr.value.length == 0 )
				{
					alert("Please enter Schedule Name");
					ScheduleDescr.focus();
					return false;
				}
				if (ServerName.value.length == 0 )
				{
					alert("Please enter server name");
					ServerName.focus();
					return false;
				}
				if (ServerUserId.value.length == 0 )
				{
					alert("Please enter server user id.");
					ServerUserId.focus();
					return false;
				}
				if (ServerUserPwd.value.length == 0 )
				{
					alert("Please enter server password.");
					ServerUserPwd.focus();
					return false;
				}
				if (Branch.value.length == 0 )
				{
					alert("Please enter release branch.");
					Branch.focus();
					return false;
				}

				document.AddReleaseScheduleForm.submit();
				
		} 	
	
	function openReleaseScheduleDetails(ReleaseScheduleID) {
		dwin=window.open("EditReleaseSchedule.jsp?releaseScheduleID="+ReleaseScheduleID,"detailWin","width=700,height=300,scrollbars=yes,resizable=No");
		dwin.focus();
		
		}

	function openAddNewAdmin(){
		dwin=window.open("AdminUserManagement.jsp?","detailWin","width=700,height=160,scrollbars=yes,resizable=No");
		dwin.focus();
	
	}
	
	</script>
</head>

<body>
<table width="100%">
	<tr>
		<td width=100%><jsp:include page="HeaderNav_ReleaseObject.jsp" /></td>
	</tr>
</table>
<%
			String AddRelScheduleButton = request
			.getParameter("AddRelScheduleButton") == null ? ""
			: request.getParameter("AddRelScheduleButton");

			if (AddRelScheduleButton.equals("Add")) {
		
				boolean addSuccessFlag = false;				
				String ScheduleDescr = request
						.getParameter("ScheduleDescr") == null ? ""
						: request.getParameter("ScheduleDescr");
				String ServerName = request.getParameter("ServerName") == null ? ""
						: request.getParameter("ServerName");
				String ServerUserId = request
						.getParameter("ServerUserId") == null ? ""
						: request.getParameter("ServerUserId");
				String ServerUserPwd = request
						.getParameter("ServerUserPwd") == null ? ""
						: request.getParameter("ServerUserPwd");
				String Branch = request.getParameter("Branch") == null ? ""
						: request.getParameter("Branch");
				String ScheduleReleaseName = request
						.getParameter("ScheduleReleaseName") == null ? ""
						: request.getParameter("ScheduleReleaseName");
		
				addSuccessFlag = dbutil.addReleaseSchedule(ScheduleDescr, ServerName,
						ServerUserId, ServerUserPwd, Branch,
						ScheduleReleaseName, userid);
				
				if(addSuccessFlag == false){
					%>
					<script>
							alert("Same Release Schedule Name already exists, Kindly enter different name.");
					</script>
					<% 
				}

			}

			Vector relNameVector = dbutil.getAllReleaseName();
			Vector relScheduleVector = dbutil.getReleaseSchedules();
%>




<a href="mainpage.jsp">Back to Main.</a>
<a href="ReleaseAdmin.jsp">Back to Admin Page</a>
<table>
	<tr>
		<td align=right>&nbsp</td>
	</tr>
</table>


<form name="AddReleaseScheduleForm" action="ReleaseSchedule.jsp"
	method="post">
<table cellpadding="0" cellspacing="1" width="50%"
	style="BORDER:#000000 1px solid" align='center' colspan=2>

	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=2><b>Add Release
		Schedule Information</b></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Schedule Name</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type=text name="ScheduleDescr" size="40"></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Server Name</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type=text name="ServerName" size="40"></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Server User
		Id</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type=text name="ServerUserId" size="40"></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Server
		Password</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type="password" name="ServerUserPwd" size="40"></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Branch</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type="text" name="Branch" size="40"></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Select
		Release</td>
		<td class=bodyblue><select name=ScheduleReleaseName>

			<%
					for (int i = 0; i < relNameVector.size(); i++) {
					ReleaseVO relbean = (ReleaseVO) relNameVector
							.elementAt(i);
			%>

			<option value='<%=	relbean.getReleaseName()%>'><%=relbean.getReleaseName()%>
			</option>

			<%
			}
			%>
		</select></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class="bodyblue" colspan="2" align="right"><input
			type=submit class=whitebutton name=AddRelScheduleButton value="Add"
			onclick="return checkForEmpty(ScheduleDescr,ServerName,ServerUserId,ServerUserPwd,Branch)"
			align=right></td>
	</tr>

</table>
</form>


<table>
	<tr>
		<td>&nbsp</td>
	</tr>
</table>
<table cellpadding="0" cellspacing="1" width="90%"
	style="BORDER:#000000 1px solid" align='center' colspan=5>
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=5><b>Release Schedules</b></td>
	</tr>

	<%
				if (relScheduleVector != null
				&& relScheduleVector.size() > 0) {
	%>
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left width='5%' colspan=1><b>#</b></td>
		<td class=smallfonthead align=left width='20%' colspan=1><b>Schedule Name</b></td>
		<td class=smallfonthead align=left width='30%' colspan=1><b>Server Name</b></td>
		<td class=smallfonthead align=left width='25%' colspan=1><b>Release Name</b></td>
		<td class=smallfonthead align=left width='20%' colspan=1><b>Branch</b></td>
	</tr>	
	<% 
			for (int i = 0; i < relScheduleVector.size(); i++) {
				ScheduleBean scheduleBean = (ScheduleBean) relScheduleVector
				.elementAt(i);
	%>


	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=center><%=i + 1%></td>
		<td class=bodyblue align=left><a
			href="javascript:openReleaseScheduleDetails('<%=scheduleBean.getReleaseScheduleKey()%>')"><%=scheduleBean.getScheduleDescr()%></a></td>
		<td class=bodyblue align=left><%=scheduleBean.getServerName()%></td>
		<td class=bodyblue align=left><%=scheduleBean.getScheduleReleaseName()%></td>	
		<td class=bodyblue align=left><%=scheduleBean.getBranch()%></td>
	</tr>
	
	

	<%
				}
				} else {
	%>
	<tr bgcolor=#000077>
		<td class=smallfonthead align="center" colspan=5><b>Not any Release Schedules found...</b></td>
	</tr>
	<%
	}
	%>
</table>



</body>
</html>





<%
	}
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
